<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>评估准则构建展示</title>
    <meta name="description" content="评估准则构建软件">
    <!-- Bootstrap CSS -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- 字体CSS -->
    <link href="assets/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/bootstrap-select/bootstrap-select.css" rel="stylesheet" type="text/css" />
    <!-- 自定义样式 -->
    <link href="assets/css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="./assets/layui/css/layui.css">
    <link rel="stylesheet" href="./assets/css/norm/normTemplete.css">
    <style>

    </style>
</head>

<body class="adminbody">
<div id="main">
    <!-- 头部导航 -->
    <div class="headerbar">
        <!-- LOGO -->
        <div class="headerbar-left">
            <a href="index.html" class="logo">
                <!--					<img alt="Logo" src="assets/images/logo.png" />-->
                <span>评估准则构建软件</span>
            </a>
        </div>

        <nav class="navbar-custom">
            <ul class="list-inline float-right mb-0">
                <li class="list-inline-item dropdown notif">
                    <a class="nav-link dropdown-toggle arrow-none" data-toggle="dropdown" href="#" role="button"
                       aria-haspopup="false" aria-expanded="false">
                        <i class="fa fa-fw fa-bell-o"></i><span class="notif-bullet"></span>
                    </a>
                    <div class="dropdown-menu dropdown-menu-right dropdown-arrow dropdown-lg">
                        <!-- item-->
                        <div class="dropdown-item noti-title">
                            <h5><small><span class="label label-danger pull-xs-right">1</span>消息提醒</small></h5>
                        </div>
                        <!-- item-->
                        <a href="#" class="dropdown-item notify-item">
                            <div class="notify-icon bg-faded">
                                <img src="assets/images/avatars/avatar2.png" alt="img"
                                     class="rounded-circle img-fluid">
                            </div>
                            <p class="notify-details">
                                <b>Admin</b>
                                <span>用户信息注册成功</span>
                                <small class="text-muted">3分钟前</small>
                            </p>
                        </a>
                        <!-- All-->
                        <a href="#" class="dropdown-item notify-item notify-all">
                            查看所有消息
                        </a>

                    </div>
                </li>

                <li class="list-inline-item dropdown notif">
                    <a class="nav-link dropdown-toggle nav-user" data-toggle="dropdown" href="#" role="button"
                       aria-haspopup="false" aria-expanded="false">
                        <img src="assets/images/avatar.jpg" alt="Profile image" class="avatar-rounded">
                    </a>
                    <div class="dropdown-menu dropdown-menu-right profile-dropdown ">
                        <!-- item-->
                        <div class="dropdown-item noti-title">
                            <h5 class="text-overflow"><small>Hello, admin</small> </h5>
                        </div>

                        <!-- item-->
                        <a href="pro-profile.html" class="dropdown-item notify-item">
                            <i class="fa fa-user"></i> <span>个人中心</span>
                        </a>

                        <!-- item-->
                        <a href="#" class="dropdown-item notify-item">
                            <i class="fa fa-power-off"></i> <span>退出</span>
                        </a>
                    </div>
                </li>

            </ul>

            <ul class="list-inline menu-left mb-0">
                <li class="float-left">
                    <button class="button-menu-mobile open-left">
                        <i class="fa fa-fw fa-bars"></i>
                    </button>
                </li>
            </ul>

        </nav>

    </div>
    <!-- 头部导航End -->
    <!-- 左侧导航开始 start-->
    <div class="left main-sidebar">
        <div class="sidebar-inner leftscroll">
            <div id="sidebar-menu">
                <ul>
                    <li class="submenu">
                        <a href="index.html"><i class="fa fa-fw fa-home"></i><span>评估准则首页</span> </a>
                    </li>
                    <li class="submenu">
                        <a href="normCreate.html" ><i class="fa fa-fw fa-check-circle-o"></i><span>评估准则生成</span> </a>
                    </li>
                    <li class="submenu">
                        <a href="normEdit.html"><i class="fa fa-fw fa-pencil-square-o"></i><span>评估准则编辑</span> </a>
                    </li>
                    <li class="submenu">
                        <a href="normEdit.html"><i class="fa fa-fw fa-bars"></i><span>评估准则展示</span> </a>
                    </li>
                    <li class="submenu">
                        <a href="normTemplete.html" class="active"><i class="fa fa-fw fa-file-text-o"></i><span>评估准则模板</span> </a>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
    <!-- End 左侧导航 -->
    <div class="content-page">
        <div class="norm-tem">
            <div class="norm-switch">
                <div class="demoTable">
                    搜索：
                    <div class="layui-inline">
                        <input class="layui-input" name="id" id="demoReload" autocomplete="off">
                    </div>
                    <button class="layui-btn" data-type="reload">搜索</button>
                </div>
            </div>
            <!-- Start content -->
            <!-- 数据表 -->
            <div class="content table-content">
                <table class="layui-hide" id="test" lay-filter="test"></table>
            </div>
        </div>

    </div>
</div>
<!-- 左边工具栏 -->
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <div class="table-tool-left">

        </div>
        <div class="table-tool-right tool-bar">
            <button class="layui-btn" lay-event="addData" style="margin-right: 15px;">
                <i class="fa fa-fw fa-plus"></i>
            </button>
            <button class="layui-btn" lay-event="getDeleteData" >
                <i class="fa fa-fw fa-trash-o"></i>
            </button>
        </div>

    </div>
</script>
<!-- 右边工具栏 -->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit" style="color:#fff;">编辑</a>
</script>



<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script src="assets/js/modernizr.min.js"></script>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/moment.min.js"></script>
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>


<script src="assets/js/detect.js"></script>
<script src="assets/js/fastclick.js"></script>
<script src="assets/js/jquery.blockUI.js"></script>
<script src="assets/js/jquery.nicescroll.js"></script>
<script src="assets/js/bootstrap-select/bootstrap-select.js"></script>

<!-- App js -->
<script src="assets/js/pikeadmin.js"></script>
<script src="./assets/layui/layui.js"></script>

<script>
    var dateRange=``,paramArr=["name","type","number","unit","forces","inParam","outParam","stateInfo","useAddr"],editId;
    layui.use(['form'], function () {

    });
    // 数据表格
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#test',
            url:'/bs/modelManage/getAllModel',
            method:'POST'
            //,contentType: 'application/json'
            // ,where:{modelName:document.getElementById('demoReload').value}
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: []
            ,title: '用户数据表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                // ,{field:'id', title:'ID',  fixed: 'left', width:60,unresize: true,align:'center'}
                ,{field:'sort', title:'序号', width:60,unresize: true,align:'center',type:'numbers'}
                ,{field:'modelName', title:'模板名称',align:'center'}
                ,{field:'context', title:'内容',align:'center'}
                ,{field:'method', title:'指标',align:'center'}
                ,{field:'category', title:'类别',align:'center'}
                ,{field:'target', title:'评估对象',align:'center'}
                ,{field:'creater', title:'创建人',align:'center'}
                ,{field:'createTime', title:'创建时间',align:'center'}
                ,{field:'frequency', title:'使用次数',align:'center'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo',align:'center'}
            ]]
            ,page: {
                layout: [ 'prev', 'page', 'next', 'count','limit',  'skip']//自定义分页布局
                ,limit:10
                ,limits:[10,20,30]
                ,first: false //不显示首页
                ,last: false //不显示尾页
            }
            ,request: {
                pageName: 'currentPage' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.status, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.totalCount, //解析数据长度
                    "data": res.data.lists //解析数据列表
                };
            },
            id:"testReload"
        });
        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var checkData = checkStatus.data,checkArr=[];
            console.log(checkData)
            //数据id 获取
            if (checkData.length>0){
                for (let i of  checkData){
                    checkArr.push(i.id);
                }
            }
            //工具栏
            switch(obj.event){
                case 'addData':
                    handleEdit("","add");
                    editId='';
                case 'getDeleteData':
                    if (checkArr.length>0){
                        layer.confirm('确认要删除吗？', {
                            btn: ['确认','取消'] //按钮
                        }, function(){
                            $.ajax({
                                //请求方式
                                type : "POST",
                                //请求的媒体类型
                                contentType: "application/x-www-form-urlencoded",
                                //请求地址
                                url : "/bs/modelManage/deleteModels",
                                //数据，json字符串
                                data : {ids:checkArr.join(',')},
                                //请求成功
                                success : function(res) {
                                    if (res.status==0){
                                        layer.msg('删除成功！',{time:2000});
                                        //刷新数据
                                        $(".layui-laypage-btn")[0].click();
                                    }else {
                                        layer.msg('删除失败！',{time:2000});
                                    }
                                },
                                //请求失败，包含具体的错误信息
                                error : function(e){
                                    console.error(e.status);
                                    console.error(e.responseText);
                                }
                            });
                        });
                    }
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                handleEdit(data);
                editId=data.id;
            }
        });

        //    监听输入，重载
        var $ = layui.$, active = {
            reload: function(){
                var demoReload = $('#demoReload');
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where:{
                        modelName: demoReload.val()
                    }
                }, 'data');
            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    //新增及修改提交、准则生成
    function getInfo(obj,check) {
        var btnType=document.getElementById("normIframe").contentWindow.btnType;
        if (btnType=='add'&&editId){
            var normData=Object.assign(obj,{modelId:editId});
            $.ajax({
                //请求方式
                type : "POST",
                //请求的媒体类型
                contentType: "application/x-www-form-urlencoded",//application/x-www-form-urlencoded,application/json
                //请求地址
                url : "/bs/modelManage/addStandard",
                //数据
                data:normData,
                //请求成功
                success : function(res) {
                    if (res.status==0){
                        layer.closeAll();
                        layer.msg('准则提交成功！');
                    }else {
                        layer.msg('准则提交失败！');
                    }
                },
                //请求失败，包含具体的错误信息
                error : function(e){
                    console.error(e.status);
                    console.error(e.responseText);
                }
            });
        }else {
            //更换字段名
            var name=obj.standardName;
            delete (obj["standardName"]);
            obj["modelName"]=name;
            if (editId){
                var setData=Object.assign(obj,{id:editId});
                $.ajax({
                    //请求方式
                    type : "POST",
                    //请求的媒体类型
                    contentType: "application/x-www-form-urlencoded",//application/x-www-form-urlencoded,application/json
                    //请求地址
                    url : "/bs/modelManage/updateModel",
                    //数据，json字符串
                    data:setData,
                    //请求成功
                    success : function(res) {
                        if (res.status==0){
                            layer.closeAll();
                            layer.msg('修改成功！');
                            //刷新数据
                            $(".layui-laypage-btn")[0].click();
                        }else {
                            layer.msg('修改失败！');
                        }
                    },
                    //请求失败，包含具体的错误信息
                    error : function(e){
                        console.error(e.status);
                        console.error(e.responseText);
                    }
                });
            }else {
                var addData=Object.assign(obj,{flag:check});
                $.ajax({
                    //请求方式
                    type : "POST",
                    //请求的媒体类型
                    contentType: "application/x-www-form-urlencoded",//application/x-www-form-urlencoded,application/json
                    //请求地址
                    url : "/bs/modelManage/insertModel",
                    //数据，json字符串
                    data:addData,
                    //请求成功
                    success : function(res) {
                        if (res.status==0){
                            layer.closeAll();
                            layer.msg('提交成功！');
                            //刷新数据
                            $(".layui-laypage-btn")[0].click();
                        }else {
                            layer.msg('提交失败！');
                        }
                    },
                    //请求失败，包含具体的错误信息
                    error : function(e){
                        console.error(e.status);
                        console.error(e.responseText);
                    }
                });
            }
        }
    }
    //	编辑
    function handleEdit(data,type){
        layer.open({
            type: 1 //Page层类型
            ,area: ['1400px', '650px']
            ,title: false
            ,shade: 0.4 //遮罩透明度
            ,maxmin: false //允许全屏最小化
            ,anim: 1 //0-6的动画形式，-1不开启
            ,content:`<iframe src="./normModule.html" frameborder="0" scrolling ='no' id="normIframe"></iframe>`
            ,success: function(layer, index){
                var normIframe=document.getElementById("normIframe");
                normIframe.onload=function (){
                    if (type=="add"){
                        normIframe.contentWindow.fillVal("");
                        normIframe.contentWindow.postType('tem');
                    }else {
                        normIframe.contentWindow.fillVal(data);
                        normIframe.contentWindow.postType('temEdit');
                    }
                }
            }
        });
    }
</script>
</body>

</html>